from osgeo import ogr
import os

shpfile = os.path.join(os.getcwd(),"include","dataset","shp.shp")

if os.path.exists(shpfile):
    drv: ogr.Driver= ogr.GetDriverByName("Esri shapefile")
    datasource:ogr.DataSource = drv.Open(shpfile,1)
    layer:ogr.Layer = datasource.GetLayer(0)

    list = []
    layerDefn: ogr.FeatureDefn= layer.GetLayerDefn()
    for i in range(layerDefn.GetFieldCount()):
        index = layerDefn.GetFieldDefn(i).GetName()
        list.append(index)
    
    feature:ogr.Feature = ogr.Feature(layerDefn)
    feature.SetField(list[0], 99)
    feature.SetField(list[1], 'GDAL')
    feature.SetField(list[2], 'PYTHON')
    feature.SetGeometry(ogr.Geometry(ogr.wkbPoint).AddPoint(119.5,35.5))
    layer.CreateFeature(feature)
    datasource.Destroy()
else:
    print("shapefile not exist, please check your files")